
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO
CREATE PROCEDURE [dbo].[LoginHostUpdate]
    @Id INT ,
    @Hostname VARBINARY(MAX) ,
    @Autologin BIT
AS 
    BEGIN
        DECLARE @AutoLoginUsersCount INT 
        SELECT  @AutoLoginUsersCount = COUNT(*)
        FROM    dbo.LoginHost
        WHERE   LoginHost.Hostname = @Hostname
                AND LoginHost.Autologin = 1 
	
        IF ( @AutoLoginUsersCount > 0 ) 
            BEGIN
                UPDATE  dbo.LoginHost
                SET     LoginHost.Autologin = 0
                WHERE   LoginHost.Hostname = @Hostname 
            END
	
        UPDATE  dbo.LoginHost
        SET     LoginHost.Autologin = @Autologin
        WHERE   LoginHost.Id = @Id
	
    END
GO
